import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wanxiang_app/bean/agreement_entity.dart';
import 'package:wanxiang_app/bean/normal_entity.dart';
import 'package:wanxiang_app/pages/msg/chat.dart';
import 'package:wanxiang_app/utils/constant.dart';
import '../../bean/service_list_entity.dart';
import '../../utils/network_manager.dart';
import '../../utils/network_url.dart';
import '../../utils/toast_util.dart';
import '../../widgets/myappbar.dart';
import 'package:get/get.dart';

class AgreeController extends GetxController{
  String title = '';
  @override
  void onInit() {
    super.onInit();
    // _getService();
    title = Get.arguments;
    _getService();
  }
  String content = '';
  @override
  void onClose() {
    super.onClose();
  }
   List<ServiceListData> list = [];
  void _getService(){
    String url = '';
    if(title =='用户协议'){
      url = ServiceUrl.agreement;
    }else{
      url = ServiceUrl.privacy;
    }
    DioManager.getInstance().post(url,null, (data) async {
      AgreementEntity bannerEntity = AgreementEntity.fromJson(jsonDecode(data));
      content = bannerEntity.data.content;
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }
}


class AgreementPage extends GetView<AgreeController>  {
  late AgreeController controller ;
  late BuildContext context ;
  @override
  Widget build(BuildContext context1) {
    Get.lazyPut<AgreeController>(() => AgreeController());
    controller = Get.find();
    context = context1;

    return GetBuilder<AgreeController>(
      builder: (_){
        return  Scaffold(
            appBar: MyAppBar(context: context, title: controller.title,hasLeading: true,),
            backgroundColor: Colors.white,
            body:_content());
      },
    );

  }
  Widget _content(){
    return SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.only(left: 20.w,top: 20.h,right: 20.w,bottom: 20.h),
          child: _contents(),
        )
    ) ;
  }


  Widget _contents(){
    return Column(
      children: [
        Html(data: controller.content),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            InkWell(
              onTap: (){
                Get.back();
              },
              child:  Container(
                margin: EdgeInsets.only(top: 20.h),
                alignment: Alignment.center,
                width: 150.w,
                height: 30.h,
                decoration: BoxDecoration(
                    color: Colors.blue,
                    borderRadius: BorderRadius.circular(5.r)
                ),
                child: Text('已阅读并同意',style: TextStyle(
                    color: Colors.white
                ),),
              )
            )

          ],
        )

      ],
    );
  }





}